-
Notifications
You must be signed in to change notification settings - Fork 574
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add KIP1 patching support (with 2 FS patches included) #51
Conversation
Thanks I'll take a look on this when possible. Currently on vacations. About the size:
We'll see.. For now I want to continue having only one binary. BTW, what's the payload size with this PR and the menu logo? |
these are all with -O2 119285/126296 without ctcaer logo (which is how im building it atm) simply stubbing print_mmc_info() gets it to compiling most functions with -Os except some time critical ones might be the way to go, if it doesnt become an organizational nightmare |
Almost 2 kilos, hmm... Thanks. Edit: |
you know where hekate switches the stack to SDRAM ? you can use that opportunity to make minimal code that runs at boot, and the rest can just be a binary embedded into rodata that you lz4 decompress into ram and jump to at that point (but this requires splitting everything into stage1 and stage2, maybe not worth doing if you can just shave off a KB by combining all the sdram parameters into one lz4 block you decompress and then choose) |
Offtopic: thanks guys, I think hekate will be superior that account-pwner ripoff program. |
I believe modularity is the best solution here. No features need to be removed. |
tried with all compression done like so Doing this with the MENU_LOGO enabled reduces the size from 128197 to 127437 bytes, still over 126296, but a cost saving of 760 bytes total (which means this pull request with MENU_LOGO still enabled is only 1141 bytes over) |
There are several reasons I keep this logo in the menu. Also, I did the tests before with lz4. Well don't worry about that. It's out of the scope of this PR. |
I don't find this lz4 noticably slower for what it's used for (the logos and sdram config) ? If you really want slower/more memory hungry, i have LZMA... which cant even be used for sdram because of the memory requirements, but it would make all your logos like 2x smaller. EDIT: reverted, lz4 is in its own branch if you want it |
This new BLZ decompression code is 2.5x faster (1472ms vs previous 3458ms on O2 and 8114ms vs previous 13458ms on Os) and also consumes 100 bytes less code space ! |
By compressing the boot/menu logo with BLZ, this is finally below the payload size threshold ! Payload size is 126089 To compress i used |
I'm really eager to test there, but it's difficult for me to follow and test these with just a phone, so here are 2 questions:
Edit: |
It's ok for the loader, don't know about the size, FS is 1.37MB compressed but 4.2MB uncompressed for the largest one, however recompression would take infeasibly long on the BPMP its not even an option (a better way would be to only uncompress .text section of FS since that's where the patches are applied to, ill take note of that) the size performance of each compressor is very dependent on the data you feed it, BLZ fared very badly on the sdram parameters compared to even LZ77, but it beat out LZ4 (which beats out LZ77) for your boot images, so use the one that compresses your data best, silly to test them out on BOOT0 which is a bunch of incompressible data like signatures and encrypted pkg1, with long strings of zeroes of padding |
Decompressing only .text of 5.1.0 exfat kip1 makes the size grow from 1.370 to 2.103 MB only, much better than decompressing everything to 4.2 MB, so i am definitely going to separate out the patches by section and only decompress ones that are absolutely necessary |
I like the direction you are going. Normally not needed but for projects like this it's a great optimization! |
Payload size is 126269 anyway, FS kip1 decompression time is now just 654ms and only an additional 800KB is used compared to compressed, so its about as good as its gonna get. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should not hang inside secondary functions (like pkg2 ones).
Also when hanging or returning from main functions, we must always umount the sd card. Even if we only read from it. This helps with avoiding corruption and voltage spikes on forced power off or removal of card.
Also please squash your commits if possible.
ipl/pkg2.c
Outdated
@@ -292,6 +482,255 @@ void pkg2_merge_kip(link_t *info, pkg2_kip1_t *kip1) | |||
pkg2_add_kip(info, kip1); | |||
} | |||
|
|||
void pkg2_decompress_kip(pkg2_kip1_info_t* ki, u32 sectsToDecomp) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function should return an int
ipl/pkg2.c
Outdated
{ | ||
u32 compClearMask = ~sectsToDecomp; | ||
if ((ki->kip1->flags & compClearMask) == ki->kip1->flags) | ||
return; //already decompressed, nothing to do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return 0
ipl/pkg2.c
Outdated
if (blz_uncompress_srcdest(srcDataPtr, compSize, dstDataPtr, outputSize) == 0) | ||
{ | ||
gfx_printf(&gfx_con, "%kERROR decomping sect %d of %s KIP!%k\n", 0xFFFF0000, sectIdx, (char*)hdr.name, 0xFFCCCCCC); | ||
while (1) { } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
free(newKip);
return 1;
ipl/pkg2.c
Outdated
free(ki->kip1); | ||
ki->kip1 = newKip; | ||
ki->size = newKipSize; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return 0
ipl/pkg2.c
Outdated
#ifdef DEBUG_PRINTING | ||
u32 preDecompTime = get_tmr_us(); | ||
#endif | ||
pkg2_decompress_kip(ki, bitsAffected); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (pkg2_decompress_kip(ki, bitsAffected))
return "decompress_failed";
ipl/pkg2.c
Outdated
if (memcmp(&kipSectData[currOffset], currPatch->srcData, currPatch->length) != 0) | ||
{ | ||
gfx_printf(&gfx_con, "%kDATA MISMATCH FOR PATCH AT OFFSET 0x%x!!!%k\n", 0xFFFF0000, currOffset, 0xFFCCCCCC); | ||
while (1) {} //MUST hang here, means the patch writer messed up |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return "data_mismatch";
or sth.
ipl/hos.c
Outdated
if (unappliedPatch != NULL) | ||
{ | ||
gfx_printf(&gfx_con, "%kREQUESTED PATCH '%s' NOT APPLIED!%k\n", 0xFFFF0000, unappliedPatch, 0xFFCCCCCC); | ||
while(1) {} //MUST hang here, because if user requests 'nogc' but it's not applied, their GC controller gets updated! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should either free stuff and return as failed or
add sd_unmount();
before while.
Additionally I was amazed to see that BLZ is almost as fast in decompression as LZ77 and has better compression than LZ4 in normal compressible data (like logos)! |
Payload size is 126293 What do you want squashed ? Everything into one or just some of them ? Squashing on the PR branch would pretty much ruin this entire discussion thread as it points to code and commits, which is why maintainers usually just squash on merge if needed. |
Everything into one. I don't mind squashing it myself. So it's your choice (raj authored and ctc committed or raj committed). |
Squashed. |
Thanks. |
Add KIP1 patching support (with 2 FS patches included)
Currently supported patches are nogc (Disable GC comms) and nosigchk (Allow unsigned NCA loading).
They are supplied via launch configuration's kip1patch variable, of which there can be multiple, or they can be comma separated
The README and sample INI have also been updated to reflect this.
Currently the CTCaer logo must be disabled, otherwise the payload exceeds maximum size. Switching to -Os decreases size significantly so the logo can be enabled, but this slows down FS KIP1 decompression from 3.5s to 10.1s !! So some compromise must be made in between (maybe removing some really rarely used tools/dumping options?)